package com.caiyouxi.system.service.impl;

import com.caiyouxi.common.bean.QueryParams;
import com.caiyouxi.common.bean.ResData;
import com.caiyouxi.common.cache.RedisService;
import com.caiyouxi.common.service.BaseService;
import com.caiyouxi.system.mapper.SysProductLineMapper;
import com.caiyouxi.system.model.SysProductLine;
import com.caiyouxi.system.service.SysProductLineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class SysProductlineServiceImpl  extends BaseService implements SysProductLineService{
    @Autowired
    private SysProductLineMapper mapper;

    @Autowired
    RedisService redisService;
    @Override
    public ResData add(SysProductLine bean) {
        return success(mapper.insert(bean));
    }

    @Override
    @Transactional
    public ResData delete(SysProductLine bean) {
        return success(mapper.delete(bean.getCode()));
        /*Integer result = 0;
        try {
            int len = bean.length;
            String[] code = new String[len];
            for(int i = 0; i < len; i ++){
                code[i] = bean[i].getCode();
            }
            result = mapper.delete(code);
        }catch (Exception e){
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        }
        return success(result);*/
    }

    @Override
    public ResData update(SysProductLine bean) {
        return success(mapper.update(bean));
    }

    @Override
    public ResData get_list(SysProductLine bean) {
        Integer pageSize = Integer.parseInt(redisService.get("sys.pagesize").toString());//后台获取默认每页多少调数据
        Integer p = bean.getPage_size();                            //查看前台是否给了每页几条数据
        if(p == 0 || p == null){
            p = pageSize;                                           //如果没给数据，则取默认数据
        }
        bean.setPage_size(p);
        QueryParams pageList = new QueryParams();
        pageList.setList(mapper.get_all(bean));                     //获取数据
        pageList.setPage(bean.getPage());                           //第几页
        pageList.setTotal(mapper.get_total_count(bean));
        pageList.setPage_size(bean.getPage_size());
        return success(pageList);
    }

    @Override
    public ResData get_info(SysProductLine bean) {
        return success(mapper.select_info(bean.getCode()));
    }
}
